package yja.gzw.app.adapter

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import yja.gzw.app.R

class NeituAdapter(private val context: Context, private val list: List<String>): RecyclerView.Adapter<RecyclerView.ViewHolder>(){
    private var view: View?=null
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        view= LayoutInflater.from(parent.context).inflate(R.layout.item_view_neitu,parent,false)
        Log.e("图片地址展示","走到了2")
        return ViewHodeView(view!!)
    }

    override fun getItemCount(): Int {
       return list.size
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
       if(holder is ViewHodeView){
           val requestOptions = RequestOptions()
               .transform(CenterCrop(), RoundedCorners(15)) // 设置圆角半径为16像素


           Glide.with(context).load(list[position])
               .apply(requestOptions)
               .into(holder.neitu)

       }


    }

    inner class ViewHodeView(itemView: View):RecyclerView.ViewHolder(itemView){
        val neitu: ImageView =itemView.findViewById(R.id.neitu)

    }



}